<?php

namespace App\Http\Middleware;

use App\Enums\Common\CodeEnum;
use App\Http\Controllers\Common\ApiHelper;
use Closure;
use Illuminate\Http\Request;

class ApiCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return  mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if (empty(auth('api')->user())){
            return ApiHelper::responseError([],'Token已过期，请重新登录！',CodeEnum::CODE_CHECK_AUTH);
        }
        return $next($request);
    }
}
